package com.example.football.controller;

import com.example.football.pojo.Newskey;
import com.example.football.pojo.Peopleliketeam;
import com.example.football.service.NewskeyService;
import com.example.football.service.PeopleliketeamService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class NewskeyController {
    @Resource
    private NewskeyService cc;

    //全查
    @RequestMapping("newskeylist")
    public String queryAll(Model model) {
        List<Newskey> list = cc.queryAll();
        //存入model
        model.addAttribute("list", list);
        //控制跳转

        return "newskeylist";
    }

    @RequestMapping("removeByNewskeyid")
    public String removeByNewskeyid(Integer id) {
        try {
            cc.removeByNewskeyid(id);
            return "redirect:/newskeylist";
        } catch (Exception e) {
            return "error";
        }
    }

    @PostMapping("findByNewskey")
    public String findByNewskey(String keyz, Model model){
        List<Newskey> list = cc.queryByNewskey(keyz);
        //存入model
        model.addAttribute("list", list);
        return "newskeylist";
    }



    @RequestMapping("addNewskeyPage")
    public String addNewskeyPage() {
        return "addnewskey";
    }

    @RequestMapping("addNewskey")
    public String addNewskey(Newskey newskey) {
        try {
            cc.addNewskey(newskey);
            return "redirect:/newskeylist";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }



    @GetMapping("findById6")
    public String findById(Integer id, Model model){
        Newskey list = cc.queryById(id);
        //存入model
        model.addAttribute("list", list);
        return "updatenewskey";
    }

    //数据修改
    @PostMapping("updateNewskey")
    public String changeNewskey(Newskey newskey) {
        try {
            cc.changeNewskey(newskey);
            return "redirect:/newskeylist";
        } catch (Exception e) {
            return "error";
        }
    }
}
